package main

import (
	"base/global"
	"base/initialize"
	"base/router"
	"github.com/spf13/viper"
	"os"
)

func init() {
	v := viper.New()
	v.AddConfigPath("resource")
	v.SetConfigType("yaml")
	if err := v.ReadInConfig(); err != nil {
		os.Exit(0)
	}
	if err := v.Unmarshal(&global.Config); err != nil {
		os.Exit(0)
	}
}

func main() {
	initialize.InitLogger()
	db, err := initialize.Gorm()
	if err != nil {
		global.Logger.Fatal(err)
	}
	global.DB = db
	defer initialize.DisConnectDB()
	initialize.DBMigrate()
	if err = router.MapRouter().Run(global.Config.System.Port); err != nil {
		global.Logger.Fatal(err)
	}
}
